package qx.hyj.petrescue.service.impl;


import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import qx.hyj.petrescue.dto.LoginUser;
import qx.hyj.petrescue.entity.Users;
import qx.hyj.petrescue.mapper.Usermapper;
import qx.hyj.petrescue.service.UserService;
import qx.hyj.petrescue.util.JWTUtil;


import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

@Service
public class userServiceImpl implements UserService {
    @Resource
    private Usermapper usermapper;

    @Override
    public String login(LoginUser loginUser) {
        Users user = new Users(null,loginUser.getAccount(),loginUser.getPassword(),null,null,null,null,null);
        List<Users> list = usermapper.searchByColumn(user);
        if(list.size() == 1){
            return JWTUtil.createToken(list.get(0).getId());
        }
        return null;
    }

    @Override
    public Users addUser(Users user) {
        String phat = "http://localhost:8080/images/head/tx1.jpg";
        user.setAvatar(phat);
        Integer addUser = usermapper.addUser(user);
        if(addUser == 1){
            return user;}else {
            return null;
        }
    }

    @Override
    public Integer updateUser(Users user, Users condition) {
       return usermapper.updateUser(user,condition);
    }


}
